//
//  SINAStudentSettingViewController.m
//  sinashebao
//
//  Created by  androidlongs on 2017/12/21.
//  Copyright © 2017年  androidlongs. All rights reserved.
//

#import "SINALoginViewController.h"
#import "SINANavLoginViewController.h"
#import "SINAStudentCountSafeViewController.h"
#import "SINAlertPasswordViewController.h"
#import "SINASettingAlertPasswordViewController.h"
#import "SINAStudentAlertPhoneViewController.h"
#import "SINAStudentAlertQQViewController.h"
#import "SINAStudentAlertWeiChatViewController.h"
#import "sdkDef.h"
#import "PTQQSdkCall.h"
#import "PTWeChatSdkCall.h"
#import "WXApiManager.h"

@interface SINAStudentCountSafeViewController ()<TencentSessionDelegate,TencentLoginDelegate,WXApiManagerDelegate>
{
    UILabel *aboutMeLabel;
    UILabel *clearLabel;
     time_t loginTime;
    UISwitch  * qqSwitch;
    UISwitch  * weChatSwitch;
}

@property(nonatomic,strong) UIScrollView *scrollView;


@property(nonatomic,strong)UILabel *phoneInputStartLabel;

@end

@implementation SINAStudentCountSafeViewController

-(void)dealloc
{
    [WXApiManager sharedManager].delegate = self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self configNavigationItem];
    self.scrollView=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, mainW, mainH)];
    self.scrollView.contentSize = CGSizeMake(mainW, mainH+1);
    [self.scrollView setBackgroundColor:[UIColor colorWithHexString:@"#eeeeee"]];
    [self.view addSubview:self.scrollView];
    
    //账号安全
    UIView *typeView  = [[UIView alloc]initWithFrame:CGRectMake(0, 15, mainW, 47)];
    [typeView setBackgroundColor:[UIColor whiteColor]];
    UILabel *typeLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, mainW-24, 45)];
    typeLabel.text=@"更换手机号";
    [typeLabel setTextColor:[UIColor colorWithHexString:@"#2e2e2e"]];
    [typeView addSubview:typeLabel];
    
    UILabel *phoneInputStartLabel = [[UILabel alloc]initWithFrame:CGRectMake(mainW-155, 0, 140, 45)];
    [phoneInputStartLabel setTextColor:[UIColor colorWithHexString:@"#878787"]];
    phoneInputStartLabel.text=@"未绑定";
    phoneInputStartLabel.textAlignment=NSTextAlignmentRight;
    [typeView addSubview:phoneInputStartLabel];
    
    self.phoneInputStartLabel=phoneInputStartLabel;
    
    [[SINAUiviewClickLiserner alloc]viewClickFunction:typeView andWithBlick:^(UIView *view) {
        [self countSafeClickFunction];
    }];
    
    UIImageView *typeImageView=[[UIImageView alloc]initWithFrame:CGRectMake(mainW-22, 45/2-13/2, 7, 13)];
    typeImageView.image=[UIImage imageNamed:@"右箭头"];
    UIView *startDiviView =[[UIView alloc]initWithFrame:CGRectMake(18, 46, mainW-18-15, 1)];
    [startDiviView setBackgroundColor:[UIColor colorWithHexString:@"#eeeeee"]];
    
    [typeView addSubview:typeLabel];
    //[typeView addSubview:typeImageView];
    [typeView addSubview:startDiviView];
    
    [self.scrollView addSubview:typeView];
    
    SINAUserModel *userModel = [[SINACommonUserHelper share]getUserModel];
    
    //微信号
    UIView *clearView  = [[UIView alloc]initWithFrame:CGRectMake(0, 77, mainW, 47)];
    [clearView setBackgroundColor:[UIColor whiteColor]];
    clearLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, mainW-24, 45)];
    //    clearLabel.text=@"微信号(烦死了)";
    [clearLabel setTextColor:[UIColor colorWithHexString:@"#2e2e2e"]];
    
    weChatSwitch = [self createSwitchFunc];
    weChatSwitch.tag = 111;
    [clearView addSubview:weChatSwitch];
    
    [weChatSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(clearView);
        make.size.mas_equalTo(CGSizeMake(49.0f, 31.0f));
        make.right.mas_equalTo(clearView).with.offset(-12.0f);
    }];
    
    if (userModel.weixinopenid!=nil && userModel.weixinopenid.length!=0 && ![userModel.weixinopenid isEqualToString:@""] && ![userModel.weixinopenid isEqualToString:@"(null)"]) {
        
        weChatSwitch.on = YES;
        clearLabel.text = [NSString stringWithFormat:@"微信号(%@)",userModel.weixinnickname];
    }
    else
    {
        weChatSwitch.on = NO;
        clearLabel.text = @"微信号";
    }
    
    [[SINAUiviewClickLiserner alloc]viewClickFunction:clearView andWithBlick:^(UIView *view) {
        [self clearCountClickFunction];
    }];
    
    UIImageView *clearImageView=[[UIImageView alloc]initWithFrame:CGRectMake(mainW-22, 45/2-13/2, 7, 13)];
    clearImageView.image=[UIImage imageNamed:@"右箭头"];
    UIView *clearDiviView =[[UIView alloc]initWithFrame:CGRectMake(18, 45, mainW-18-15, 1)];
    [clearDiviView setBackgroundColor:[UIColor colorWithHexString:@"#eeeeee"]];
    
    [clearView addSubview:clearLabel];
    //[clearView addSubview:clearImageView];
    [clearView addSubview:clearDiviView];
    
    [self.scrollView addSubview:clearView];
    
    
    //QQ账号
    UIView *aboutMeView  = [[UIView alloc]initWithFrame:CGRectMake(0, 123, mainW, 45)];
    [aboutMeView setBackgroundColor:[UIColor whiteColor]];
    aboutMeLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, mainW-24, 45)];
    //    aboutMeLabel.text=@"QQ(烦死了)";
    [aboutMeLabel setTextColor:[UIColor colorWithHexString:@"#2e2e2e"]];
    
    qqSwitch = [self createSwitchFunc];
    qqSwitch.tag = 222;
    [aboutMeView addSubview:qqSwitch];
    
    [qqSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(aboutMeView);
        make.size.mas_equalTo(CGSizeMake(49.0f, 31.0f));
        make.right.mas_equalTo(aboutMeView).with.offset(-12.0f);
    }];
    
    if (userModel.qqopenid!=nil && userModel.qqopenid.length!=0 && ![userModel.qqopenid isEqualToString:@""] && ![userModel.qqopenid isEqualToString:@"(null)"]) {
        
        qqSwitch.on = YES;
        aboutMeLabel.text = [NSString stringWithFormat:@"QQ(%@)",userModel.qqnickname];
    }
    else
    {
        qqSwitch.on = NO;
        aboutMeLabel.text = @"QQ";
    }
    
    [[SINAUiviewClickLiserner alloc]viewClickFunction:aboutMeView andWithBlick:^(UIView *view) {
        [self aboutMeClickFunction];
    }];
    
    UIImageView *aboutMeImageView=[[UIImageView alloc]initWithFrame:CGRectMake(mainW-22, 45/2-13/2, 7, 13)];
    aboutMeImageView.image=[UIImage imageNamed:@"右箭头"];
    
    
    [aboutMeView addSubview:aboutMeLabel];

    [self.scrollView addSubview:aboutMeView];
    
    //更改密码
    UIView *selectView  = [[UIView alloc]initWithFrame:CGRectMake(0, 183, mainW, 47)];
    [selectView setBackgroundColor:[UIColor whiteColor]];
    UILabel *selectLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 0, mainW-24, 45)];
    selectLabel.text=@"更改密码";
    [selectLabel setTextColor:[UIColor colorWithHexString:@"#2e2e2e"]];
    [selectView addSubview:selectLabel];
    
    [[SINAUiviewClickLiserner alloc]viewClickFunction:selectView andWithBlick:^(UIView *view) {
        [self selectIdentClickFunction];
    }];
    
    [self.scrollView addSubview:selectView];
    
    loginTime = 0;
    
}

#pragma mark - QQ Notification method
#pragma mark - QQ Delegate method
- (void)tencentDidLogin
{
    if (![[PTQQSdkCall getInstance].oauth getUserInfo]) {
        
        DLog(@"获取用户信息失败");
    }
}
/**
 * 登录失败后的回调
 * \param cancelled 代表用户是否主动退出登录
 */
- (void)tencentDidNotLogin:(BOOL)cancelled
{
    
}

/**
 * 登录时网络有问题的回调
 */
- (void)tencentDidNotNetWork
{
    
}

- (void)getUserInfoResponse:(APIResponse*) response
{
    NSString * openId =[PTQQSdkCall getInstance].oauth.openId;
    NSDictionary *message = response.jsonResponse;
    
    if (openId == nil || openId.length ==0) {
        return;
    }
    
    //检测是否已绑定其他手机号
     [self checkIsBindOpenId:openId nickName:[message objectForKey:@"nickname"] bindTag:1];
}

-(void)checkIsBindOpenId:(NSString *)openid nickName:(NSString *)nickname bindTag:(NSInteger)bindTag
{
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    
    if (bindTag ==1) {
        //qq
        [dict setObject:openid forKey:@"qqopenid"];
    }
    else if (bindTag == 2)
    {
        //微信
        [dict setObject:openid forKey:@"weixinopenid"];
    }
    
    WeakSelf;
    
    [CXAFNHttpRequestUtils httpGetRequest:[NSString stringWithFormat:@"%@%@",baseUrl,kPT_Interface_URI_ishas]  withParamters:dict success:^(id responseData) {
        
        NSString *code = responseData[@"code"];
        if ([code isEqualToString:@"1000"]) { //未绑定
            
            if (bindTag ==1) {
                [weakSelf BindOrUnBind:1 openId:openid nickName:nickname isBind:YES];
            }
            else if(bindTag ==2)
            {
                [weakSelf BindOrUnBind:2 openId:openid nickName:nickname isBind:YES];
            }
            
        }
        else
        {
            NSString * message = nil;
            if (bindTag ==1) {
                message = @"该QQ已绑定其他肆迹账号";
                qqSwitch.on = NO;
            }
            else if(bindTag ==2)
            {
                message = @"该微信已绑定其他肆迹账号";
                weChatSwitch.on = NO;
            }
            WISAlertView * alertView = [[WISAlertView alloc]initWithTitle:@"绑定失败" message:message sureBtn:@"确定" cancleBtn:@"取消"];
            [alertView showXLAlertView];
        }
        
    } failure:^(NSError *error, NSInteger errCode) {
        
        
    }];
}

-(UISwitch *)createSwitchFunc{
    
    UISwitch  *switchFunc = [[UISwitch alloc]init];
    //    [switchFunc setTintColor:[UIColor grayColor]];
    [switchFunc setOnTintColor:[UIColor colorWithHexString:@"#349Ef7"]];
    //    [switchFunc setThumbTintColor:[UIColor whiteColor]];
    switchFunc.layer.cornerRadius = 15.5f;
    switchFunc.layer.masksToBounds = YES;
    [switchFunc addTarget:self action:@selector(switchAction:) forControlEvents:UIControlEventTouchUpInside];
    return switchFunc;
}

-(void)switchAction:(UISwitch *)sender
{
    if (sender.tag ==111) {
        
        //微信
        if (weChatSwitch.isOn) {
            
            weChatSwitch.on = NO;
            
            //去绑定
            [self sendAuthRequest];
        }
        else
        {
            weChatSwitch.on = YES;
        
            //解绑
            WISAlertView * alertView = [[WISAlertView alloc]initWithTitle:@"提示" message:@"确定要解除已绑定的微信号?" sureBtn:@"确定" cancleBtn:@"取消"];
            [alertView showXLAlertView];
            
            WeakSelf;
            alertView.resultIndex = ^(NSInteger index) {
                //解绑
                [weakSelf BindOrUnBind:2 openId:@"" nickName:@"" isBind:NO];
            };

//            alertView.cancleIndex = ^(NSInteger index)
//            {
//                weChatSwitch.on = YES ;
//            };
        }
    }
    else if (sender.tag ==222)
    {
        //QQ
        if (qqSwitch.isOn) {
    
            qqSwitch.on = NO;
            //为了初始化以下sdk
            DLog(@"QQ 登录");
            time_t currentTime;
            time(&currentTime);
            if ((currentTime - loginTime)>2) {
                
                NSString * appid = __TencentSDKAppid_;
                [PTQQSdkCall getInstance].oauth =[[TencentOAuth alloc]initWithAppId:appid andDelegate:self];
                
                TencentOAuth * oauth = [[PTQQSdkCall getInstance]oauth];
                oauth.authMode = kAuthModeClientSideToken;
                [oauth authorize:[self getPermissions] inSafari:NO];
                loginTime = currentTime;
            }
        }
        else
        {
            
            qqSwitch.on = YES;
            
            WISAlertView * alertView = [[WISAlertView alloc]initWithTitle:@"提示" message:@"确定要解除已绑定的QQ账号?" sureBtn:@"确定" cancleBtn:@"取消"];
            [alertView showXLAlertView];
            
            WeakSelf;
            
           alertView.resultIndex = ^(NSInteger index) {
               //解绑
               [weakSelf BindOrUnBind:1 openId:@"" nickName:@"" isBind:NO];
           };
            
//            alertView.cancleIndex = ^(NSInteger index)
//            {
//                qqSwitch.on = YES;
//            };
            
        }
    }
}

- (void)sendAuthRequest {
    
    [WXApiManager sharedManager].delegate = self;
    
    BOOL isOpenWenxin = [PTWeChatSdkCall sendAuthRequestScope: kAuthScope
                                        State:kAuthState
                                       OpenID:kAuthOpenID
                             InViewController:self];

    NSLog(@"%d",isOpenWenxin);
}

#pragma mark WXApiManagerDelegate Method

- (void)managerDidRecvAuthResponse:(SendAuthResp *)response
{
//    NSString *strTitle = [NSString stringWithFormat:@"Auth结果"];
//    NSString *strMsg = [NSString stringWithFormat:@"code:%@,state:%@,errcode:%d", response.code, response.state, response.errCode];
//    NSLog(@"%@---%@",strMsg,strTitle);
    
    if (response.errCode == -4)
    {
        WISAlertView * alertView = [[WISAlertView alloc]initWithTitle:@"提示" message:@"拒绝授权" sureBtn:@"确定" cancleBtn:@""];
        [alertView showXLAlertView];
    }
    else if (response.errCode == -2)
    {
        WISAlertView * alertView = [[WISAlertView alloc]initWithTitle:@"提示" message:@"已取消" sureBtn:@"确定" cancleBtn:@""];
        [alertView showXLAlertView];
    }
    else
    {
        NSString * urlStr = [NSString stringWithFormat:@"https://api.weixin.qq.com/sns/oauth2/access_token?appid=%@&secret=%@&code=%@&grant_type=authorization_code",@"wx35768a01f369dc62",@"0aad08c8483fc7ddbcbfde7f937532ff",response.code];

        WeakSelf;
        [CXAFNHttpRequestUtils httpGetRequest:urlStr success:^(id responseData) {
            
            DLog(@"responseData === %@",responseData);
            
            [WXApiManager sharedManager].access_token = [responseData objectForKey:@"access_token"];
            [WXApiManager sharedManager].openid = [responseData objectForKey:@"openid"];
            [WXApiManager sharedManager].scope = [responseData objectForKey:@"scope"];
            [WXApiManager sharedManager].unionid = [responseData objectForKey:@"unionid"];
            
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1), dispatch_get_main_queue(), ^{
                
                [weakSelf getWeChatUserInfo];
            });
            
        } failure:^(NSError *error, NSInteger errCode) {
            
            
        }];
    }
}

-(void)getWeChatUserInfo
{
    NSString * infoUrlStr = [NSString stringWithFormat:@"https://api.weixin.qq.com/sns/userinfo?access_token=%@&openid=%@",[WXApiManager sharedManager].access_token,[WXApiManager sharedManager].openid];
    
    WeakSelf;
    [CXAFNHttpRequestUtils httpGetRequest:infoUrlStr success:^(id responseData) {
        
        //如果请求成功
        [WXApiManager sharedManager].nickname = [responseData objectForKey:@"nickname"];
        
        //调用绑定接口
        
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1), dispatch_get_main_queue(), ^{
            
             [weakSelf checkIsBindOpenId:[WXApiManager sharedManager].openid nickName:[WXApiManager sharedManager].nickname bindTag:2];
        
        });
        
    } failure:^(NSError *error, NSInteger errCode) {
        

    }];
}

-(void)BindOrUnBind:(NSInteger)bindTag openId:(NSString *)openId nickName:(NSString *)nickName isBind:(BOOL)isBind
{
    SINAUserModel *userModel = [[SINACommonUserHelper share]getUserModel];
    
    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    
    [dict setObject:userModel.userUid forKey:@"uuid"];
    if (bindTag ==1) {
        //QQ
        if (isBind) {
            [dict setObject:openId forKey:@"qqopenid"];
            [dict setObject:nickName forKey:@"qqnickname"];
        }
        else
        {
            [dict setObject:@"" forKey:@"qqopenid"];
            [dict setObject:@"" forKey:@"qqnickname"];
        }
    }
    else if (bindTag ==2)
    {
           //微信
        if (isBind) {
            [dict setObject:openId forKey:@"weixinopenid"];
            [dict setObject:nickName forKey:@"weixinnickname"];
        }
        else
        {
            [dict setObject:@"" forKey:@"weixinopenid"];
            [dict setObject:@"" forKey:@"weixinnickname"];
        }
    }
   
    
    NSMutableDictionary *dict2 = [[NSMutableDictionary alloc]init];
    [dict2 setObject:[SINAHttpRequestUtils encodeDicParams:dict] forKey:@"sj"];
    
    [self startLoading];
    WeakSelf;
    [CXAFNHttpRequestUtils httpPostRequest:[NSString stringWithFormat:@"%@%@",baseUrl,userAlertInformationUrl] withParamters:dict2 success:^(id responseData) {
        
        [weakSelf stopLoading];
        
        NSString *code = responseData[@"code"];
        
        if ([code isEqualToString:@"1000"]) {
            
            if (bindTag ==1) {
                //qq
                if (isBind) {
                    userModel.qqopenid=openId;
                    userModel.qqnickname=nickName;
                    
                    qqSwitch.on = YES;
                    aboutMeLabel.text = [NSString stringWithFormat:@"QQ(%@)",userModel.qqnickname];
                }
                else
                {
                    userModel.qqopenid=@"";
                    userModel.qqnickname=@"";
                    qqSwitch.on = NO;
                    aboutMeLabel.text = @"QQ";
                    
                    NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
                    [userDefaults removeObjectForKey:@"qqopenid"];
                    [userDefaults removeObjectForKey:@"qqnickname"];
                    [userDefaults synchronize];
                    
                    [PTQQSdkCall getInstance].oauth = nil;
                }
            }
            else if (bindTag ==2)
            {
                //微信
                if (isBind) {
                    userModel.weixinopenid=openId;
                    userModel.weixinnickname=nickName;
                    weChatSwitch.on = YES;
                    clearLabel.text = [NSString stringWithFormat:@"微信号(%@)",userModel.qqnickname];
                }
                else
                {
                    userModel.weixinopenid=@"";
                    userModel.weixinnickname=@"";
                    
                    NSUserDefaults * userDefaults = [NSUserDefaults standardUserDefaults];
                    [userDefaults removeObjectForKey:@"weixinopenid"];
                    [userDefaults removeObjectForKey:@"weixinnickname"];
                    [userDefaults synchronize];
                    
                    weChatSwitch.on = NO;
                    clearLabel.text = @"微信号";
                    [WXApiManager sharedManager].delegate = nil;
                     [WXApiManager sharedManager].openid = nil;
                }
            }

            [[SINACommonUserHelper share] saveUserModel:userModel];
            
            if (isBind) {
                
                  [YPXToastView showToastViewWithText:@"已绑定" andDuration:1 andParentView:weakSelf.view];
            }else
            {
                  [YPXToastView showToastViewWithText:@"已解绑" andDuration:1 andParentView:weakSelf.view];
            }

        }
        else if ([code isEqualToString:@"1002"])
        {
            if (isBind) {
                
                [YPXToastView showToastViewWithText:@"绑定失败" andDuration:1 andParentView:weakSelf.view];
            }else
            {
                [YPXToastView showToastViewWithText:@"解绑失败" andDuration:1 andParentView:weakSelf.view];
            }
        }
        
    } failure:^(NSError *error, NSInteger errCode) {
        [weakSelf stopLoading];
    }];
}

-(void)viewDidAppear:(BOOL)animated{
    self.navigationController.navigationBarHidden = NO;
}
-(void)configNavigationItem{
    self.navigationController.navigationBarHidden = NO;
    self.navigationItem.title=@"账号安全";
    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0/255 green:198.0/255 blue:174.0/255 alpha:0.8f];
    self.navigationController.navigationBar.translucent = NO;
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],
                                                                      NSForegroundColorAttributeName:[UIColor whiteColor]}];
}

- (NSMutableArray *)getPermissions
{
    NSMutableArray * g_permissions = [[NSMutableArray alloc] initWithObjects:kOPEN_PERMISSION_GET_USER_INFO,
                                      kOPEN_PERMISSION_GET_SIMPLE_USER_INFO,
                                      kOPEN_PERMISSION_ADD_ALBUM,
                                      kOPEN_PERMISSION_ADD_ONE_BLOG,
                                      kOPEN_PERMISSION_ADD_SHARE,
                                      kOPEN_PERMISSION_ADD_TOPIC,
                                      kOPEN_PERMISSION_CHECK_PAGE_FANS,
                                      kOPEN_PERMISSION_GET_INFO,
                                      kOPEN_PERMISSION_GET_OTHER_INFO,
                                      kOPEN_PERMISSION_LIST_ALBUM,
                                      kOPEN_PERMISSION_UPLOAD_PIC,
                                      kOPEN_PERMISSION_GET_VIP_INFO,
                                      kOPEN_PERMISSION_GET_VIP_RICH_INFO, nil];
    
    return g_permissions;
}

-(void)viewWillAppear:(BOOL)animated{
    SINAUserModel *userModel = [[SINACommonUserHelper share] getUserModel];
    if (userModel!=nil&&userModel.userPhone!=nil&&![userModel.userPhone isEqualToString:@""]) {
        self.phoneInputStartLabel.text=userModel.userPhone;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


//更换手机号
-(void)countSafeClickFunction{
    SINAStudentAlertPhoneViewController *alertPhonwController = [[SINAStudentAlertPhoneViewController alloc]initWithNibName:@"SINAStudentAlertPhoneViewController" bundle:nil];
    [self.navigationController pushViewController:alertPhonwController animated:YES];
}

//绑定微信号
-(void)clearCountClickFunction{
    //    SINAStudentAlertWeiChatViewController *alertPasswordController = [[SINAStudentAlertWeiChatViewController alloc]initWithNibName:@"SINAStudentAlertWeiChatViewController" bundle:nil];
    //    [self.navigationController pushViewController:alertPasswordController animated:YES];
}
//绑定QQ号
-(void)aboutMeClickFunction{
    //    SINAStudentAlertQQViewController *alertPasswordController = [[SINAStudentAlertQQViewController alloc]initWithNibName:@"SINAStudentAlertQQViewController" bundle:nil];
    //    [self.navigationController pushViewController:alertPasswordController animated:YES];
}
//更改密码
-(void)selectIdentClickFunction{
    
    SINASettingAlertPasswordViewController *alertPasswordController = [[SINASettingAlertPasswordViewController alloc]initWithNibName:@"SINASettingAlertPasswordViewController" bundle:nil];
    [self.navigationController pushViewController:alertPasswordController animated:YES];
}

//退出登录
-(void)exitLoginClickFunction{
    
    WISAlertView *alertView =   [[WISAlertView alloc]initWithTitle:@"提示" message:@"确定退出登录?" sureBtn:@"确定"
                                                         cancleBtn:@"取消"];
    __weak typeof(self) weakSelf = self;
    alertView.resultIndex = ^(NSInteger index) {
        //清除数据
        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults setObject:@"" forKey:@"userId"];
        [defaults setObject:@"" forKey:@"userUid"];
        [defaults setObject:@"" forKey:@"userToken"];
        
        
        NSString *identitys = @"";
        
        [defaults setObject:identitys forKey:@"identitys"];
        //登录页面
        SINALoginViewController *rootViewControll = [[SINALoginViewController alloc]init ];
        SINANavLoginViewController *homeController = [[SINANavLoginViewController alloc] initWithRootViewController:rootViewControll];
        weakSelf.view.window.rootViewController = homeController;
        [weakSelf.view.window makeKeyAndVisible];
    };
    [alertView showXLAlertView];
    
    
}


/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end

